package com.briup.app01.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.app01.bean.Category;
import com.briup.app01.service.ICategoryService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@RequestMapping("/category")
@Api(description = "栏目管理")
@RestController
public class CategoryController {

	@Autowired
	private ICategoryService icategoryService;

	// 保存一个Category
	@ApiOperation(value = "保存或者修改一个栏目信息", notes = "如果id为空是保存反之是更新")
	@GetMapping("/saveOrUpdate")
	public String saveOrUpdate(Category category) {
		icategoryService.saveOrUpdate(category);
		return "保存成功";
	}

	// 查询所有的Category
	@ApiOperation("查询所有栏目信息")
	@GetMapping("/findAll")
	public List<Category> findAll() {
		return icategoryService.findAll();
	}

	// 查询单个Category
	@ApiOperation("查询一个栏目信息")
	@ApiImplicitParam(name = "id", value = "栏目id", required = true)
	@GetMapping("/findById")
	public Category findById(long id) {
		return icategoryService.findById(id);
	}

	// 删除单个信息
	@ApiOperation("删除一个栏目信息")
	@GetMapping("/deleteById")
	public String deleteById(long id) {
		icategoryService.deleteById(id);
		return "删除成功";
	}

	// 模糊查询
	@ApiOperation("根据栏目名称进行模糊查询")
	@GetMapping("/findNameLike")
	public List<Category> findNameLike(String name) {
		return icategoryService.findLikeName(name);

	}

}
